package com.teame.readbaby.util;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/**
 * 线程池管理类
 * @author dupengtao
 *
 */
public class ThreadPoolManager {
	private ExecutorService service;//dpt:线程池
	/**
	 * 单例，你懂的
	 */
	private ThreadPoolManager(){
		int num = Runtime.getRuntime().availableProcessors();//dpt:Returns the number of processors available to the VM,
		service = Executors.newFixedThreadPool(num*2);//dpt:创建一个可重用固定线程数的线程池，以共享的无界队列方式来运行这些线程。
	}
	
	private static final ThreadPoolManager manager= new ThreadPoolManager();
	
	public static ThreadPoolManager getInstance(){
		return manager;
	}
	
	public void addTask(Runnable runnable){
		service.execute(runnable);//dpt:在未来某个时间执行给定的命令。
	}
}
